<div class="_contro">
    <a href="/home/coupon/" class="_a"><font style='font-size:1.5rem'>返回列表页</font></a>
</div>
<div class='_cut'></div>
<div class='content'>   
    <form action="/home/coupon/submit" method="post" id='form'>
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">所属门店:</label>
            <select name='store'>
                <option>请选择门店</option>
                <?php  foreach($_store as $v){?>
                <option value='<?php echo $v['id'];?>' <?php if($v['id']==$barber['store_id'] || (int)$coupon['store_id']==$v['id'] ){echo "selected='selected'";}?>><?php echo $v['name'];?></option>
                <?php } ?>
            </select>
        </div>
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">优惠劵名称:</label>
            <input type="text" class="row _minput" name='name' id='name' placeholder="" value="<?php echo $coupon['name'] ?>" style="width:15rem;"/>
        </div>         
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >优惠劵类型:</label>
            <select name="type_name" class='_select' id='type_name'>
                <option value="折扣券" <?php if($coupon['type_name']=="折扣券"){echo "selected='selected'";}?>>折扣券</option>
                <option value="现金券" <?php if($coupon['type_name']=="现金券"){echo "selected='selected'";}?>>现金券</option>
                <option value="体验券" <?php if($coupon['type_name']=="体验券"){echo "selected='selected'";}?>>体验券</option> 
            </select>
        </div> 
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">优惠劵折扣:</label>
            <input type="text" name="content" id="content" placeholder="折扣数" value="<?php echo $coupon['content'] ?>" style="width:5rem;"><span id='yuan'>折</span>&nbsp;&nbsp;
            店内消费满<input type='text' name='condition' id='condition' placeholder='可不填' value='<?php echo $coupon['condition']?>' style="width:5rem;">元使用
        </div>
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">优惠劵数量:</label>
            <input type="text" class="row _minput" name='num' placeholder=""  value="<?php if($coupon['num']){echo $coupon['num'];} ?>" style="width:15rem;"/>
            <span class="_prompt">请填写优惠劵数量小于100张</span>
        </div>
        <!-- <div class="form-group row">
                    <label for="exampleInputName2" class="_label">优惠劵样式:</label>
                    <select name="style" class='_select'>
                        <option value="1" <?php if($coupon['style']==1){echo "selected='selected'";}?>>样式1</option>
                    </select>
        </div> -->
        <input type='hidden' name='style' value="1" >
        <?php if($coupon['start_time']!=''){ ?>
        <div id='model'>
            
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">开始日期:</label>
                <input type="text" class="row _minput" name='start_time' placeholder="" value="<?php echo date('Y-m-d',$coupon['start_time']) ?>" onfocus="WdatePicker();" onblur=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">结束日期:</label>
                <input type="text" class="row _minput" name='end_date' placeholder="" value="<?php echo date('Y-m-d',$coupon['end_date']) ?>" onfocus="WdatePicker();" onblur=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">使用截止时间:</label>              
                <input type="text" class="row _minput" name='end_time' placeholder="" value="<?php echo date('Y-m-d',$coupon['end_time']) ?>" onfocus="WdatePicker();" onblur=""/>
            </div>
            
        </div>
        <?php }else{?>
        <div id='model'>    
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">开始日期:</label>
                <input type="text" class="row _minput" name='start_time' placeholder="" value="" onfocus="WdatePicker();" onblur=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">结束日期:</label>
                <input type="text" class="row _minput" name='end_date' placeholder="" value="" onfocus="WdatePicker();" onblur=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">使用截止时间:</label>              
                <input type="text" class="row _minput" name='end_time' placeholder="" value="" onfocus="WdatePicker();" onblur=""/>
            </div>
            
        </div>
        <?php }?>
        <div class='form-group row'>
            <label for="exampleInputName2" class="_label">优惠劵说明:</label>
        </div>
        <div class='form-group row'>
            <textarea style="margin-left:5rem;width:40rem;" name='intro' id="_intro" class="_textarea" placeholder="可不写"><?php echo $coupon['intro']; ?></textarea>

        </div>
        <?php if(!$coupon || $coupon['status']==0){?>
        <div class="form-group _submit_div row">
            <input name='coupon_id' type='hidden'  value="<?php echo $coupon['id']?>">
            <input name='create' id='create' class='_button' type="button" value="预览" onclick="_submit(2);"/>
            <input name='caogao' id='caogao' class='_button' type="submit" value="保存草稿" onsubmit="return _submit(1);"/>
        </div>
        <?php } ?>
    </form>

</div>

<script type='text/javascript' src='/public/js/date/WdatePicker.js'></script>

<script type='text/javascript'>
                $(document).ready(function () {


                    $("#form").validate({
                        rules: {
                            store:{
                                required: true,
                                min:1
                            },
                            name: {
                                required: true,
                                rangelength: [0, 11],
                            },
                            num: {
                                required: true,
                                range: [-1, 100],
                            },
                            start_time: {
                                required: true,
                            },
                            end_time: {
                                required: true,
                            },
                            end_date: {
                                required: true,
                            },
                            content: {
                                required: true,
                            }

                        },
                        messages: {
                            store:{
                                required: '请选择店铺',
                                min: '请选择店铺'
                            },
                            name: {
                                required: '请填写优惠劵名称',
                                rangelength: '请填写字数小于11个',
                            },
                            num: {
                                required: '请填写优惠劵数量',
                                range: '请填写数量小于100',
                            },
                            start_time: {
                                required: '请选择开始使用日期',
                            },
                            end_time: {
                                required: '请选择结束使用日期',
                            },
                            end_date: {
                                required: '请选择领取结束日期',
                            },
                            content: {
                                required: '请填写优惠劵折扣',
                            }
                        }
                    });
                });

                function _submit(type) {
                    if (type == 1) {
                        $('#create').remove();
                    } else {
                        $('#caogao').remove();
                    }
                    $('#form').submit();
                }

                $("#type_name").change(function () {
                    var num = '';
                    if ($("#type_name").val() == "现金券") {
                        num = 1;
                    } else if ($("#type_name").val() == "折扣券") {
                        num = 0;
                    } else {
                        num = 2;
                    }
                    $.ajax({
                        url: "/home/coupon/ajax?num=" + num,
                        async: true,
                        success: function (data) {
                            if (data == "false") {
                                return;
                            } else if (data == 1) {
                                $('#content').attr('placeholder', "金额");
                                $("#yuan").html('元');
                            } else if (data == 0) {
                                $('#content').attr('placeholder', "折扣数");
                                $("#yuan").html('折');
                            } else if (data == 2) {
                                $('#content').attr('placeholder', "金额");
                                $("#yuan").html('元');
                            }
                        }
                    });
                });
                if ($("#type_name").val() == "现金券") {
                    $('#content').attr('placeholder', "金额");
                    $("#yuan").html('元');
                } else if ($("#type_name").val() == "折扣券" || $("#type_name").val() == '') {
                    $('#content').attr('placeholder', "折扣数");
                    $("#yuan").html('折');
                } else {
                    $('#content').attr('placeholder', "项目名");
                    $("#yuan").html('');
                }



</script> 
